
    
    var check_patterns = new Array();
    check_patterns['email'] = '\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b';
    check_patterns['integer'] = '\b\d+\b';
    check_patterns['decimal'] = '^([0-9]+)\.([0-9]+)$';
    
    
    var error_message;
    

    function validate_form( fields_fild_type_array )
    {
        error_message = new Array();
        var valid = true;
        

        for( field in fields_fild_type_array )
        {
            var field_element = document.getElementById(field);            
            if( field_element.value.length == 0 )
            {
                valid = false;
                error_message.push("The "+field_element.name+" field is required");
            }
            else
            {
                for(pattern in check_patterns)
                {
                    if(fields_fild_type_array[field] == pattern)
                    {
                        if( field_element.value.search(check_patterns[pattern]) == -1 )
                        {
                            valid = false;
                            error_message.push("The "+field_element.name+" is invalid "+pattern+" value");
                        }    
                    }    
                }    
            }    
        }    
        
        if(valid == false)
        {
            alert_errors();
        }    
        
        return valid;
    }
    
    function alert_errors()
    {
        var error_string = "";
        if(error_message.length > 0)
        {
            for(i=0;i<error_message.length;i++)
            {
                error_string += (i+1)+". "+error_message[i]+"\n";
            }    
        }    
        
        alert(error_string);
    }

